package cn.study.luckyapp.server;

import cn.study.luckyapp.prize.command.PrizeAddCmdExe;
import cn.study.luckyapp.prize.command.PrizeUpdateCmdExe;
import cn.study.luckyapp.prize.query.PrizeListByParamQueryExe;
import cn.study.luckyclient.api.IPrizeService;
import cn.study.luckyclient.dto.PrizeAddCmd;
import cn.study.luckyclient.dto.PrizeUpdateCmd;
import cn.study.luckyclient.dto.data.PrizeVo;
import cn.study.luckyclient.dto.query.PrizeListByParamQuery;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.io.File;

@Service
@AllArgsConstructor
public class PrizeServiceImpl implements IPrizeService {
    private final PrizeAddCmdExe prizeAddCmdExe;
    private final PrizeUpdateCmdExe prizeUpdateCmdExe;
    private final PrizeListByParamQueryExe prizeListByParamQueryExe;
    @Override
    public PrizeVo add(PrizeAddCmd cmd) {
        return prizeAddCmdExe.execute(cmd);

    }

    @Override
    public PrizeVo update(PrizeUpdateCmd cmd) {
        return prizeUpdateCmdExe.execute(cmd);
    }

    @Override
    public IPage<PrizeVo> page(PrizeListByParamQuery query) {
        return prizeListByParamQueryExe.execute(query);
    }

    @Override
    public PrizeVo one(Long id) {
        PrizeListByParamQuery prizeListByParamQuery = new PrizeListByParamQuery();
        prizeListByParamQuery.setId(id);
        IPage<PrizeVo> execute = prizeListByParamQueryExe.execute(prizeListByParamQuery);
        return execute.getRecords().get(0);
    }
}
